#include "lyricstext.h"
#define PADDING 5

LyricsText::LyricsText(QGraphicsItem* parent) : QGraphicsItem(parent) {
	cols << new QGraphicsTextItem(this) << new QGraphicsTextItem(this) << new QGraphicsTextItem(this);
}

void LyricsText::resize(QSizeF size) {
	prepareGeometryChange();
	rect = QRectF(QPoint(0,0), size);
	int x = 0;
	foreach(QGraphicsTextItem* col, cols) {
		col->setPos(x, 0);
		x += size.width()/3+PADDING;
		col->setTextWidth(size.width()/3-PADDING);
	}
}

void LyricsText::setText(QString text) {
	QStringList textCols = QStringList() << "" << "" << "";
	QStringList lines = text.split('\n');
	for(int i = 0; i < lines.size(); i++) {
		if(i <= lines.size()/3)
			textCols[0] += lines.at(i)+'\n';
		else if(i > 2*lines.size()/3)
			textCols[1] += lines.at(i)+'\n';
		else 
			textCols[2] += lines.at(i)+'\n';
	}
	for(int i = 0; i < textCols.size(); i++) {
		cols.at(i)->setPlainText(textCols.at(i));
		cols.at(i)->adjustSize();
	}
	resize(QSize(rect.width(), qMax(cols.at(0)->boundingRect().height(), cols.at(2)->boundingRect().height())));
}
